package com.example.grpc.helloworld;

import io.grpc.stub.StreamObserver;

public class GreeterImpl extends GreeterGrpc.GreeterImplBase {

    /**
     * {@inheritDoc}
     * 
     * @param request 客户端发过来的请求
     * @param responseObserver 应答的观察者，实际上是服务器调用它应答的一个特殊接口
     */
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
        HelloReply reply = HelloReply.newBuilder().setMessage("你好：" + request.getName()).build();
        //返回数据
        responseObserver.onNext(reply);
        //应答已完成
        responseObserver.onCompleted();
    }

}
